import java.util.LinkedList;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-13
 * Time: 23:16
 */
public class MinStack {

    public Stack<Integer> stack1;
    public Stack<Integer> stack2;
    public MinStack() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }

    public void push(int val) {
        this.stack1.push(val);
        if (this.stack2.empty()) {
            this.stack2.push(val);
        }else {
            int ans = this.stack2.peek();
            if (val <= ans) {
                this.stack2.push(val);
            }
        }
    }

    public void pop() {
        int ans = this.stack1.pop();
        if (ans == this.stack2.peek()) {
            this.stack2.pop();
        }
    }

    public int top() {
        return this.stack1.peek();
    }

    public int getMin() {
        return this.stack2.peek();
    }
}
